const router = require('koa-router')()
const Mock = require('mockjs');

const { list } = Mock.mock({
  "list|100": [{
    "id": "@id",
    "image": "@image(150x100, @color)",
    "title": "@ctitle",
    "desc": "@cword(10, 20)",
    "price|50-100": 1,
    "oldPrice|100-200": 1,
    "sell|1-1000": 1 
  }]
})
// 列表
router.get('/list', ctx => {
  ctx.body = {
    code: 200,
    data: list
  }
})
// 详情
router.get('/list/detail', ctx => {
  const { id } = ctx.request.query;

  const item = list.find(v => v.id === id)

  if(item) {
    ctx.body = {
      code: 200,
      data: item
    }
  } else {
    ctx.body = {
      code: 404,
      message: '为该找该项数据'
    }
  }
})

module.exports = router
